package queuedemo;

import java.util.Deque;
import java.util.LinkedList;

public class Myqueue1 {
    private Deque<Integer> deque1;
    private Deque<Integer> deque2;
    public Myqueue1(){
        deque1=new LinkedList<>();
        deque2=new LinkedList<>();
    }
    public void offer(int x){
        deque1.push(x);
    }
    public int poll(){
        if (empty()){
            return -1;
        }
        if (deque2.isEmpty()){
            while (!deque1.isEmpty()){
                deque2.push(deque1.pop());
            }
        }
        return deque2.pop();
    }
    public int peek(){
        if (empty()){
            return -1;
        }
        if (deque2.isEmpty()){
            while (!deque1.isEmpty()){
                deque2.push(deque1.pop());
            }
        }
        return deque2.peek();
    }
public boolean empty(){
        return deque1.isEmpty()&&deque2.isEmpty();
}
}
